<template>
  <div>
    <van-form @submit="onSubmit">
      <van-field
        v-model="username"
        name="手机号"
        label="手机号"
        placeholder="手机号"
        :rules="objRules.ruleArr"
      />
      <van-field
        v-model="password"
        type="password"
        name="密码"
        label="密码"
        placeholder="密码"
        :rules="objRules.arrPas"
      />
      <van-field
        v-model="sms"
        center
        clearable
        label="短信验证码"
        placeholder="请输入短信验证码"
      >
        <template #button>
          <van-button size="small" type="primary">发送验证码</van-button>
        </template>
        <template v-slot:left-icon>
          <van-icon name="fire-o" color="#ee0a24" />
        </template>
        <template slot="right-icon">
          <van-icon name="like-o" color="pink"/>
          <van-icon name="cart-o" color="#1989fa" />
        </template>
      </van-field>
      <div style="margin: 16px">
        <van-button round block type="info" native-type="submit"
          >提交</van-button
        >
      </div>
    </van-form>
  </div>
</template>
<script>
const userHandel = (value, rule) => {
  let reg = /^(0|86|17951)?(13[0-9]|15[012356789]|166|17[3678]|18[0-9]|14[57])[0-9]{8}$/
  let flag = reg.test(value)
  return flag

}
export default {
  data () {
    return {
      username: '',
      password: '',
      objRules: {
        ruleArr: [{ required: true, message: '请填写手机号' },
        // {pattern : /^(0|86|17951)?(13[0-9]|15[012356789]|166|17[3678]|18[0-9]|14[57])[0-9]{8}$/, message: '请填写合法手机号'}
        { validator: userHandel, message: '请填写合法手机号' }
        ],
        arrPas: [{ required: true, message: '请填写密码' }]
      },
      sms:''
    };

  },
  methods: {
    onSubmit (values) {
      console.log('submit', values);
    },
  },
};
</script>
<style lang='less'  scoped>
</style>
